package com.zyz.system.controller.sysuser;



import com.zyz.common.core.active.Time;
import com.zyz.common.core.constants.HttpConstants;
import com.zyz.common.core.model.LoginUserVO;
import com.zyz.common.core.model.Result;
import com.zyz.system.model.sysuser.dto.LoginDTO;
import com.zyz.system.model.sysuser.dto.SysUserSaveDTO;
import com.zyz.system.service.sysuser.ISysUserService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.enums.ParameterIn;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


@RestController
@RequestMapping("/sysUser")
@Tag(name = "管理员接口")
public class SysUserController {

    @Autowired
    private ISysUserService sysUserService;


    @Operation(summary = "管理员退出" ,description = "从前端请求头拿到token获取消息后退出")
    @RequestMapping(value = "/logout",method = RequestMethod.DELETE)
    public Result<Void> logout(@RequestHeader(HttpConstants.AUTHENTICATION) String token) {
        return sysUserService.logout(token) ? Result.ok() : Result.fail();
    }

    @Time
    @Operation(summary = "管理员登录", description = "根据提供信息登录")
    @ApiResponse(responseCode = "1000",description = "操作成功")
    @ApiResponse(responseCode = "2000",description = "服务器繁忙")
    @ApiResponse(responseCode = "3101",description = "用户已存在")
    @ApiResponse(responseCode = "3102",description = "用户不存在")
    @ApiResponse(responseCode = "3103",description = "用户名或密码错误")
    @RequestMapping(value = "/login",method = RequestMethod.POST)
    public Result<String> login(@RequestBody LoginDTO loginDTO) {
        return sysUserService.login(loginDTO.getUserAccount(), loginDTO.getPassword());
    }

    @Time
    @RequestMapping(value = "/info",method = RequestMethod.GET)
    @Operation(summary = "获取管理员信息" ,description = "从前端请求头中拿到token获取管理员信息")
    public Result<LoginUserVO> info(@RequestHeader(HttpConstants.AUTHENTICATION) String token) {
        return sysUserService.info(token);
    }

    @RequestMapping(value = "/add",method = RequestMethod.POST)
    @Operation(summary = "新增管理员", description = "根据提供的信息新增管理员")
    @ApiResponse(responseCode = "1000",description = "操作成功")
    @ApiResponse(responseCode = "2000",description = "服务器繁忙")
    @ApiResponse(responseCode = "3101",description = "用户已存在")
    @ApiResponse(responseCode = "3102",description = "用户不存在")
    @ApiResponse(responseCode = "3103",description = "用户名或密码错误")
    public Result<Void> add(@RequestBody SysUserSaveDTO sysUserSaveDTO) {
        return sysUserService.add(sysUserSaveDTO.getUserAccount(),sysUserSaveDTO.getPassword(),sysUserSaveDTO.getNickName());
    }

    @Operation(summary = "删除用户", description = "根据用户id删除用户")
    @RequestMapping(value = "/{userId}",method = RequestMethod.DELETE)
    @Parameter(name = "userId" , in = ParameterIn.PATH ,description = "从url中获取用户id")
    @ApiResponse(responseCode = "1000",description = "操作成功")
    @ApiResponse(responseCode = "2000",description = "服务器繁忙")
    @ApiResponse(responseCode = "3101",description = "用户已存在")
    @ApiResponse(responseCode = "3102",description = "用户不存在")
    @ApiResponse(responseCode = "3103",description = "用户名或密码错误")
    public Result<Void> delete(@PathVariable("userId") Long userId) {
        return null;
    }


}
